package com.project.springboot.controller;

import com.project.springboot.service.miaosha.SecondKillService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * description: 秒杀controller
 * @author 朱正磊
 * @date 2021-03-17 15:29:26
 */
@Slf4j
@RestController
@RequestMapping("/secondKill")
public class SecondKillController {

    @Resource
    private SecondKillService secondKillService;

    /**
     * description: 查询秒杀活动特价商品的信息
     * @author 朱正磊
     * @date 2021-03-17 16:47:21
     * @param productId 商品ID
     * @return 返回秒杀活动特价商品的信息
     */
    @GetMapping("/query/{productId}")
    public String query(@PathVariable("productId") String productId) {
        // 查询秒杀商品信息
        return secondKillService.querySecondKillProductInfo(productId);
    }

    /**
     * description: 秒杀商品
     * @author 朱正磊
     * @date 2021-03-17 16:48:17
     * @param productId 商品ID
     * @return 返回秒杀活动特价商品的信息
     */
    @GetMapping("/order/{productId}")
    public String secondKill(@PathVariable("productId") String productId) {
        log.info("secondKill request, productId: " + productId);
        // 模拟多线程秒杀商品
        secondKillService.mockMultithreadingOrderProduct(productId);
        // 查询秒杀商品信息
        return secondKillService.querySecondKillProductInfo(productId);
    }

}
